﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using cart.model;
using cart.dao;
using cart.utils;

namespace cart.service
{
    public class orderServiec
    {
        public Boolean addOrder(orderModel om)
        {
            orderDao od = new orderDao();
            return od.addOrder(om);
        }

        public Boolean updateOrderByOrderID(orderModel om)
        {
            orderDao od = new orderDao();
            return od.updateOrderByOrderID(om);
        }

        public orderModel getOrderByID(int orderID)
        {
            orderDao od = new orderDao();
            return od.getOrderByID(orderID);
        }

        public int saveOrder(ArrayList alCart, string username)
        {
            orderModel om = new orderModel();
            orderItemsService ois = new orderItemsService();
            int orderID = globalID.getMaxOrderID();
            om.orderID = orderID;
            om.totle = 0;
            om.userID = username;
            om.addOrderTime = DateTime.Now;

            foreach (orderItemsModel oim in alCart)
            {
                oim.orderID = om.orderID;
                om.totle = om.totle + ois.getSubTotle(oim);
            }
            addOrder(om);
            ois.addOrderItems(alCart);

            return om.orderID;
        }
    }
}
